home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / general / Point.st < prev    next >
Text File  |  2000-02-16  |  2KB  |  75 lines

  1. "---------------------------------------------------------------"
  2. " Point Class consists of ordered pairs of coordinates.         "
  3. "---------------------------------------------------------------"
  4.  
  5. Class Point :Magnitude
  6. ! xvalue yvalue !
  7. [
  8.    < aPoint
  9.       ^ (xvalue < aPoint x) and: [yvalue < aPoint y]
  10. |
  11.    <= aPoint
  12.       ^ (xvalue <= aPoint x) and: [yvalue < aPoint y]
  13. |
  14.    >= aPoint
  15.       ^ (xvalue >= aPoint x) and: [yvalue >= aPoint y]
  16. |
  17.    = aPoint
  18.       ^ (xvalue = aPoint x) and: [yvalue = aPoint y]
  19. |
  20.    * scale
  21.       ^ (Point new x: (xvalue * scale)) y: (yvalue * scale)
  22. |
  23.    + delta
  24.       ^ (Point new x: (xvalue + delta x)) y: (yvalue + delta y)
  25. |
  26.    - delta
  27.       ^ (Point new x: (xvalue - delta x)) y: (yvalue - delta y)
  28. |
  29.    / scale
  30.       ^ (Point new x: (xvalue / scale)) y: (yvalue / scale)
  31. |
  32.    // scale
  33.       ^ (Point new x: (xvalue // scale)) y: (yvalue // scale)
  34. |
  35.    abs
  36.       ^ (Point new x: xvalue abs) y: (yvalue abs)
  37. |
  38.    asString
  39.       ^ xvalue asString , ' @ ' , (yvalue asString)
  40. |
  41.    dist: aPoint
  42.       ^ ((xvalue - aPoint x) squared + 
  43.          (yvalue - aPoint y) squared) sqrt
  44. |
  45.    max: aPoint
  46.       ^ (Point new x: (xvalue max: aPoint x))
  47.          y: (yvalue max: aPoint y)
  48. |
  49.    min: aPoint
  50.       ^ (Point new x: (xvalue min: aPoint x))
  51.          y: (yvalue min: aPoint y)
  52. |
  53.    printString
  54.       ^ xvalue printString , ' @ ' , (yvalue printString)
  55. |
  56.    transpose
  57.       ^ (Point new x: yvalue) y: xvalue
  58. |
  59.    x
  60.       ^ xvalue
  61. |
  62.    x: aValue
  63.       xvalue <- aValue
  64. |
  65.    x: xValue y: yValue
  66.       xvalue <- xValue.
  67.       yvalue <- yValue
  68. |
  69.    y
  70.       ^ yvalue
  71. |
  72.    y: aValue
  73.       yvalue <- aValue
  74. ]
  75.